import {paramType} from "@/utils/index";
import {IUserInfo} from "@/redux/user/states";

const Stg = window.localStorage;
// '[object Array]' 前八位为固定值
const isObj_ARR = (val: any) => ['object', 'array'].includes(paramType(val));
export const setLocalStorage = (key: string, val: any) => key && val ? Stg.setItem(key, isObj_ARR(val) ? JSON.stringify(val) : String(val)) : false;
export const getLocalStorage = (key = 'state'):any => (key && Stg.getItem(key))
export const clearLocalStorage = () => Stg.clear();
export const setUserInfo2LocalStorage = (userInfo:IUserInfo) => {
  setLocalStorage("userInfo", userInfo)
}
export const setAccessToken2LocalStorage = (accessToken:string) => setLocalStorage('accessToken', accessToken)
